'use strict';

var path = require('path');
var webpack = require('webpack');

var config = module.exports = {
  // the base path which will be used to resolve entry points
  context: path.join(__dirname, '../', '../'),
  // the main entry point for our application's frontend JS
  entry: {
    admin: './app/frontend/javascripts/admin.js',
    dashboard: './app/frontend/javascripts/dashboard.js',
    home: './app/frontend/javascripts/home.js',
    reserves: './app/frontend/javascripts/reserves.js',
    //about: './app/frontend/javascripts/about.coffee',
    users: './app/frontend/javascripts/users.js',
    products: './app/frontend/javascripts/products.js',
    carts: './app/frontend/javascripts/carts.js',
    orders: './app/frontend/javascripts/orders.js',
    payments: './app/frontend/javascripts/payments.js',
    wiki: './app/frontend/javascripts/wiki.js',
    designers: './app/frontend/javascripts/designers.js',
    design_promotions: './app/frontend/javascripts/design_promotions.js',
    abouts: './app/frontend/javascripts/abouts.js',
    promotions: './app/frontend/javascripts/promotions.js',
    product_cases: './app/frontend/javascripts/product_cases.js'
  },
  externals: {
    jquery: 'jQuery'
  }
};

config.output = {
  // this is our app/assets/javascripts directory, which is part of the Sprockets pipeline
  path: path.join(path.join(__dirname, '../', '../'), 'app', 'assets', 'javascripts'),
  // the filename of the compiled bundle, e.g. app/assets/javascripts/bundle.js
  filename: '[name].entry.js',
  // if the webpack code-splitting feature is enabled, this is the path it'll use to download bundles
  publicPath: '/assets',
  devtoolModuleFilenameTemplate: '[resourcePath]',
  devtoolFallbackModuleFilenameTemplate: '[resourcePath]?[hash]',
  
};

config.resolve = {
  // tell webpack which extensions to auto search when it resolves modules. With this,
  // you'll be able to do `require('./utils')` instead of `require('./utils.js')`
  extensions: ['', '.js', '.coffee', '.vue'],
  // by default, webpack will search in `web_modules` and `node_modules`. Because we're using
  // Bower, we want it to look in there too
  modulesDirectories: [ 'node_modules', 'vendor/assets/bower_components', 'vendor/assets/javascripts', 'vendor/assets/javascripts/umeditor/lang/zh-cn/'],
  alias: {
    'vue$': 'vue/dist/vue.common.js'
  }
};

config.plugins = [
  // we need this plugin to teach webpack how to find module entry points for bower files,
  // as these may not have a package.json file
  new webpack.ResolverPlugin([
    new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('.bower.json', ['main'])
  ]),
  new webpack.ProvidePlugin({
    "$": 'jquery',
    "jQuery": 'jquery'
  })
  
];

config.module = {
  loaders: [
    { test: /\.vue$/, loader: 'vue-loader' },
    { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
    { test: /\.coffee$/, loader: 'coffee-loader' },
    { test: /\.css$/, loader: 'style!css!autoprefixer'},
    { test: /\.less/, loader: 'style!css!autoprefixer!less'},
    {
      test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
      loader: 'file-loader'
    },
    {
      test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
      loader: 'file-loader',
      query: {
        name: '[name].[ext]?[hash]'
      }
    }
  ],
};

